<?php
/**
 * Validierungsklasse zur Parametervalidierung
 *
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2013 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 *
 * */


/**
 * $val muss einem Eintrag des uebergebenen Arrays entsprechen
 * array('one', 'of', 'them', ...)
 * */
Class Yapary_Parameter_CheckPartOfArrayKey Extends Yapary_Exception_Error Implements Yapary_Parameter_ICheck
{
	private $in_array = NULL;
	function __construct ( array $_in_array )
	{
		$this->in_array = $_in_array;
	}


	public function typedef ( $val )
	{
		return $val;
	}


	public function getPattern ()
	{
		return NULL;
	}


	public function isValid ( $val )
	{
		if (!is_array($this->in_array) || count($this->in_array) == 0) {
			return false;
		}
		if (!isset($val)) {
			$this->addError(Yapary_Exception_Error::E_UNDEFINED);
			return false;
		}
		foreach ($this->in_array as $key => $v) {
			if ($key == $val) {
				return true;
			}
		}

		$this->addError(Yapary_Exception_Error::E_OUT_OF_LIST);
		return false;
	}
}
